<!--
 * @Author: 李天惊 uf_lee@163.com
 * @Date: 2022-08-15 16:45:26
 * @LastEditors: 李天惊 uf_lee@163.com
 * @LastEditTime: 2022-12-12 15:02:11
 * @FilePath: \grazlink20\uc_sys\src\components\Lee\Edit\src\LeeEdit.vue
 * Copyright (c) 2022 by 李天惊 uf_lee@163.com, All Rights Reserved. 
-->
<script setup lang="ts">
import { PropType, watch } from 'vue'
import { Form } from '@/components/Form'
import { useForm } from '@/hooks/web/useForm'

const props = defineProps({
  // 数据
  data: {
    type: Object as PropType<Nullable<any>>,
    default: () => null
  },
  // 结构（JSON）
  schema: {
    type: Array as PropType<FormSchema[]>,
    default: () => []
  },
  rules: {
    type: Object as PropType<any>,
    default: () => {}
  }
})
const { register, methods, elFormRef } = useForm({
  schema: props.schema
})

watch(
  () => props.data,
  (value) => {
    if (!value) return
    const { setValues } = methods
    setValues(value)
  },
  {
    deep: true,
    immediate: true
  }
)

defineExpose({
  elFormRef,
  getFormData: methods.getFormData,
  oldFormData: props.data
})
</script>

<template>
  <div>
    <Form ref="editRef" :rules="props.rules" @register="register" />
  </div>
</template>
